import time
import json
import random
from concurrent.futures import ThreadPoolExecutor, as_completed

import requests

pool = ThreadPoolExecutor(20)


def task():
    # 模拟网络IO等引起的延迟
    time.sleep(random.uniform(0, 0.5))  # 0~1之间随机的浮点数
    ret = requests.get("http://127.0.0.1:9000/get_user_infos")
    if ret.status_code == 200:
        print("ret.body: ", len(json.loads(ret.text).get("records")))


# 提交任务，开始执行线程池的任务
all_tasks = [pool.submit(task) for i in range(10000)]

# 走主线程
# 获取每个线程的返回值
for ret in as_completed(all_tasks):
    num = ret.result()

print("------END------")
